<template>
	<view class="container">
		<view class="pad-32">
			<u--form labelPosition="left" :model="info" ref="form1" labelWidth="190rpx"
				:labelStyle="{fontSize: '28rpx'}">
				<view class="bg-white pad-left-right-24 pad-top-bottom-16 radius24">

					<u-form-item label="开户银行" prop="tel" :borderBottom="true">
						<view class="flex-w" @click="hanldeType(2)">{{cardText}}</view>
					</u-form-item>

					<u-form-item label="银行卡号" prop="tel" :borderBottom="true">
						<u--input type="number" clearable placeholderClass="input-style" placeholder="请输入账户卡号"
							v-model="info.custBankAccountNo" border="none"></u--input>
					</u-form-item>

					<u-form-item label="预留手机号" prop="tel">
						<u--input type="number" clearable placeholderClass="input-style" placeholder="请输入账户开户名"
							v-model="info.custBindPhoneNo" border="none"></u--input>
					</u-form-item>

				</view>
			</u--form>

			<u-button :customStyle="{borderRadius: '12rpx'}" class="mar-top-96 font-32 button bg-theme"
				@click="submit">保存</u-button>

			<u-popup :show="selectShow" mode="bottom" round="10" closeable @close="hanldeClose">
				<view class="pad-30">
					<view class="text-center mar-bottom-30 font-30">请选择</view>
					<u-search placeholder="关键字搜索" @clear="hanldeClear" @custom="hanldeSearch"
						v-model="keyword"></u-search>
					<view class="list-box">
						<view @click="hanldeSelectId(item.code,item.title)" v-for="item in selectList"
							class="centerY betweenX border-bottom">
							<view class="text-center font-30 pad-20">{{item.title}}</view>
							<u-icon v-if="settleBankNoCode.indexOf(item.code) > -1" name="checkbox-mark"
								color="#fc1003"></u-icon>
						</view>
					</view>
					<u-button :customStyle="{borderRadius: '12rpx'}" class="mar-top-30 font-32 button bg-theme"
						@click="hanldeConfirm">确定选择</u-button>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	import {
		bindKftCard,
		dictGetAll,
		bindAdd
	} from '@/config/api.js'
	export default {
		data() {
			return {
				// 所在城市
				address: '',
				radiolist: [{
					name: '借记卡',
					value: '1',
				}, {
					name: '贷记',
					value: '2',
				}],
				// 选择弹窗
				selectShow: false,
				wifiText: '请选择开户行名称',
				cardText: '请选择你的银行卡',
				// 开户数据
				info: {
					custBankAccountNo: '',
					custBindPhoneNo: '',
				},
				// 获取卡
				cardList: [],
				// 地址数据
				addressList: [],
				// 关键字搜索
				keyword: '',
				// 枚举字段数据
				selectList: [],
				// 银行卡
				settleBankNoCode: '',
				addresCode: ''
			}
		},
		onLoad() {
			// 获取一些枚举
			this.getAllList(4);
		},
		methods: {
			// 获取枚举
			getAllList(type, title = '') {
				dictGetAll({
					gid_arr: [type],
					s_title: title
				}).then(res => {
					this.selectList = res.data.lists[type];
					this.operateList = JSON.parse(JSON.stringify(res.data.lists[type]));
				})
			},
			// 关闭弹窗
			hanldeClose() {
				this.selectShow = false;
			},
			// 切换数据
			hanldeType(e) {
				this.type = e;
				this.keyword = '';
				this.getAllList(4);
				this.selectShow = true;
			},
			// 选择银行卡类型
			groupChange(e) {
				console.log(e)
			},
			// 取消
			hanldeClose() {
				this.selectShow = false;
			},
			// 确定
			hanldeConfirm(e) {
				this.selectShow = false;
			},
			// 提交开通数据
			submit() {
				if (this.cardText == '请选择你的银行卡') {
					uni.$u.toast(this.cardText);
					return
				}

				// 请输入银行卡号
				if (this.info.custBankAccountNo == '') {
					uni.$u.toast('请输入银行卡号');
					return
				}

				// 预留手机号
				if (this.info.custBindPhoneNo == '') {
					uni.$u.toast('请输入预留手机号');
					return
				}

				let data = {
					plat_id: 13,
					kft: this.info
				}

				bindAdd(data).then(res => {
					uni.$u.toast(res.msg);
					setTimeout(() => {
						uni.navigateBack();
					}, 1000)
				})
			},
			// 点击搜索
			hanldeSearch(e) {
				this.selectList = [];
				this.operateList.forEach(item => {
					if (item.title.indexOf(e) != -1) {
						this.selectList.push(item);
					}
				})
			},
			// 清空
			hanldeClear() {
				this.selectList = this.operateList;
			},
			// 选择想要的数据
			hanldeSelectId(code, text) {
				this.settleBankNoCode = code;
				this.cardText = text;
				this.info.custBankNo = code;
			}
		}
	}
</script>

<style scoped lang="scss">
	.button {
		box-shadow: 0 10px 15px rgba(223, 0, 7, .1);
		height: 96rpx;
		color: white;
	}

	/deep/ .u-form-item__body {
		height: 100rpx;
	}

	.list-box {
		height: 50vh;
		overflow-y: scroll;
	}

	.input-style {
		color: rgb(192, 196, 204) !important;
		background: white;
	}

	.container {
		padding-top: var(--status-bar-height); //给组件加个上边距
		box-sizing: border-box;
		background: url('../../static/image/my-bg.png') no-repeat;
		background-size: 100% 100%;
		height: 100vh;
	}

	.border-bottom {
		border-bottom: 1px solid rgb(214, 215, 217);
	}

	::v-deep .uni-input-input:disabled {
		background: white;
	}
</style>